<!-- File: /app/View/Acounts/assign_pos.ctp -->

<!-- @author karim kamel -->


<html>
    <?php
    echo $this->Html->script('DragDropHelpers'); // Include jQuery library
    echo $this->Html->script('EventHelpers'); // Include jQuery library
    echo $this->Html->script('permissionForm'); // Include jQuery library
    echo $this->Html->css('permission'); // Include css library
    ?>
    <script type="text/javascript">
        function assign() //takes the lists of names and put each list in an array and pass it to the controller
        {
            var links_list1 = [];
            var links1 = document.getElementById('moderatorUsers').getElementsByTagName('a');
            for(var a in links1) {
                if(typeof links1[a] == undefined) continue;
                links_list1.push(links1[a].innerHTML);} 
            var moderatorss =links_list1.toString();
            var moderators = moderatorss.split(',');
            var moderators1 = [];
            for(i=0;i<moderators.length;i++){
                if (moderators[i]!=""){
                    moderators1[i]=moderators[i];                  
                }}
            
            var links_list2 = [];
            var links2 = document.getElementById('editorUsers').getElementsByTagName('a');
            for(var a in links2) {
                if(typeof links2[a] == undefined) continue;
                links_list2.push(links2[a].innerHTML);} 
            var editorss =links_list2.toString();
            var editors = editorss.split(',');
            var editors1 = [];
            for(i=0;i<editors.length;i++){
                if (editors[i]!=""){
                    editors1[i]=editors[i];                  
                }}
         
            if(moderators1.length == 0 && editors1.length == 0){
                moderators1[0] = "empty";
                editors1[0] = "empty";
            }                
            $.post("/tweetar/accounts/assign_pos", 
            { moderators1: moderators1, 
                editors1: editors1                
            });
           
            //alert("Changes Saved"); 
            alert(moderators1); 
            alert(editors1);
            //window.location.replace("/Accounts/assign_pos");
        }
    </script>
    <body>
        <?php $this->start('leftmenu'); ?>
        <div class="well pull-left">
            <ul class="nav nav-list">
                <li><?php echo $this->Html->link('Manage Accounts', array('controller' => 'tattlraccounts', 'action' => 'index')); ?></li>
                <li><a href="/tattlraccounts/addaccount">Add Account</a></li>
                <li><?php echo $this->Html->link('Assign Positions', array('controller' => 'Accounts', 'action' => 'assign_pos')); ?></li>
            </ul>
        </div>
        <?php $this->end(); ?>
        <form>
            <fieldset> 
                <legend>Roles Assigning ( <?php
        if (!empty($name)) {
            echo $name;
            echo ' )';
        }
        ?></legend> 

                <p>The chart below shows the users you have added to your account,
                    you can remove any user by dragging and dropping him in the remove user list.</p>

                <table class="userTable">
                    <thead>
                        <tr>
                            <th>Remove User</th>

                            <th>Moderators</th>

                            <th>Editors</th>
                        </tr>
                    </thead>

                    <tbody>
                        <tr>
                            <td id="unassignedUsers" class="userList"> <!-- inserts the unAssigned users -->

                            </td>

                            <td id="moderatorUsers" class="userList"><!-- inserts the Moderators -->
                                <?php if (!empty($mod)) {
                                    for ($i = 0; $i < $modlen; $i++) { ?>
                                        <a href="#" draggable="true"><?php echo $mod[$i]['users']['email']; ?> </a>
                                        <?php
                                    }
                                } else {
                                    
                                }
                                ?> 
                            </td>

                            <td id="editorUsers" class="userList"><!-- inserts the Editors -->
                                <?php if (!empty($edi)) {
                                    for ($i = 0; $i < $edilen; $i++) { ?>
                                        <a href="#" draggable="true"><?php echo $edi[$i]['users']['email']; ?> </a>
                                        <?php
                                    }
                                } else {
                                    
                                }
                                ?> 
                            </td>
                        </tr>
                    </tbody>
                    <tfoot>
                    <td id="unassignedUsersHelp">Drag a user to this list to to remove him from  
                        this account permanently.</td>
                    <td id="moderatorUsersHelp">Drag user here</td>
                    <td id="editorUsersHelp" >Drag user here</td>
                    </tfoot>
                </table>
            </fieldset> 
            <h1 style="display:none;"></h1>
            <button  class ="button" onClick="assign()">Save Changes</button>
        </form>

    </body>


